﻿using System.Threading;
using EmbeddedWebserver.Core;
using EmbeddedWebserver.Core.Configuration;
using EmbeddedWebserver.Core.Helpers;

namespace EmbeddedWebserver.Test
{
    public class Program
    {
        public static void Main()
        {
#if MF_FRAMEWORK_VERSION_V4_1
            EmbeddedWebapplicationConfiguration config = new EmbeddedWebapplicationConfiguration(@"SD\webroot");
            config.ReadConfiguration();            
            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface[] networkInterfaces = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
            foreach (var networkInterface in networkInterfaces)
            {
                DebugHelper.Print("Ip adress: " + networkInterface.IPAddress);                
            }
#else
            EmbeddedWebapplicationConfiguration config = new EmbeddedWebapplicationConfiguration(@"..\..\..\Webroot");
            config.ReadConfiguration();
#endif

            using (Webserver server = new Webserver(config))
            {
                server.RegisterHandler("hello", typeof(TestHandler));
                server.RegisterHandler("random", typeof(RandomHandler));
                server.RegisterThreadSafeHandler("rnd", new RandomHandler());
                server.RegisterThreadSafeHandler("post", new PostHandler());
                server.StartListening();
#if MF_FRAMEWORK_VERSION_V4_1
                Thread.Sleep(System.Threading.Timeout.Infinite);
#else
                System.Console.Write("Press [ESC] to exit ... ");
                while (System.Console.ReadKey(true).Key != System.ConsoleKey.Escape) { }                
#endif
            }
        }

    }
}
